import operator

#7 = 111b 5=101b


def f(x,y):
    if x==0 or x==1:
        if y%4==0:
            return y
        if y%4==1:
            return 1
        if y%4==2:
            return y+1
        if y%4==3:
            return 0
    else:
        return operator.xor(f(0,x-1),f(0,y))
        
def f1(ax,ay):
    ret=ax
    for i in range(ax+1,ay+1):
        ret=operator.xor(ret,i)
    return ret
    

for i in range(0,10):
    for j in range(0,10):
        if f(i,j)!=f1(i,j):
            print "not equal:i="+str(i)+"  j="+str(j)
        else:
            #print "equal"
            pass
        
print f(0,3)
print f1(0,3)
size,query_no=map(int,raw_input().split())
array=map(int,raw_input().split())

for i in range(query_no):
    lj,rj=map(int,raw_input().split())
    maxv=0
    for x in range(lj,rj+1):
        for y in range(lj,rj+1):
            if array[x-1]<=array[y-1]:
                maxv=max(maxv,f(array[x-1],array[y-1]))    
    print maxv
            